package com.octopus.kernal.util.xml;

import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.apache.commons.lang.StringUtils;

@XmlType(name="Entity")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Entity {
	
	@XmlAttribute
	private String name;
	
	@XmlAttribute
	private String alias;
	
	@XmlAttribute
	private String customized;
	
	@XmlAttribute
	private String defaultSort;
	
	@XmlAttribute
	private Boolean persist = true;
	
	@XmlAttribute
	private Integer layoutDetail = 2;
	
	@XmlAttribute
	private Integer layoutSearch = 2;
	
	@XmlElementWrapper(name="Fields")
    @XmlElement(name="Field")
    private List<Field> fields;
	
	@XmlElementWrapper(name="Keywords")
    @XmlElement(name="Keyword")
    private List<String> keywords;
	
	@XmlElementWrapper(name="Actions")
    @XmlElement(name="Action")
    private List<Action> actions;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCustomized() {
		return customized;
	}

	public void setCustomized(String customized) {
		this.customized = customized;
	}

	public List<Field> getFields() {
		return fields;
	}

	public void setFields(List<Field> fields) {
		this.fields = fields;
	}

	public String getAlias() {
		if(StringUtils.isNotBlank(alias))
			return alias;
		else
			return StringUtils.uncapitalize(name);
	}

	public void setAlias(String alias) {
		this.alias = alias;
	}

	public Integer getLayoutDetail() {
		return layoutDetail;
	}

	public void setLayoutDetail(Integer layout) {
		this.layoutDetail = layout;
	}

	public Integer getLayoutSearch() {
		return layoutSearch;
	}

	public void setLayoutSearch(Integer layoutSearch) {
		this.layoutSearch = layoutSearch;
	}

	public List<String> getKeywords() {
		return keywords;
	}

	public void setKeywords(List<String> keywords) {
		this.keywords = keywords;
	}

	public String getDefaultSort() {
		return defaultSort;
	}

	public void setDefaultSort(String defaultSort) {
		this.defaultSort = defaultSort;
	}

	public List<Action> getActions() {
		return actions;
	}

	public void setActions(List<Action> actions) {
		this.actions = actions;
	}

	public Boolean getPersist() {
		return persist;
	}

	public void setPersist(Boolean persist) {
		this.persist = persist;
	}

}
